#ifndef PORT_H
#define PORT_H

#include <stdint.h>
#include <stdbool.h>

#include <8051.h>
#include <8052.h>
#include "compiler.h"

#define LEDLattice P0   //点阵列控制端口
#define NixieTube P0    //数码管控制端口
#define KeyMatrix P1    //按键矩阵控制端口
#define LED P2          //LED控制端口

enum timer_counter_e {
    //13 bit timer/counter
    TIMER0 = 0x00,
    //16 bit timer/counter
    TIMER1 = 0x01,
    //8-bit automatic loading timer/counter
    TIMER2 = 0x02,
    //Two separate 8-bit timer counters
    TIMER3 = 0x03
};

enum enable_e {
    ENABLE = 0x0,
    DISABLE = 0x1
};

SBIT( DC_Motor , 0x90/*P1*/, 0);/*P10*/

SBIT( M_1_A , 0x90/*P1*/, 0);/*P10*/
SBIT( M_2_B , 0x90/*P1*/, 1);/*P11*/
SBIT( M_3_C , 0x90/*P1*/, 2);/*P12*/
SBIT( M_4_D , 0x90/*P1*/, 3);/*P13*/

SBIT( M_1_D , 0x90/*P1*/, 0);/*P10*/
SBIT( M_2_C , 0x90/*P1*/, 1);/*P11*/
SBIT( M_3_B , 0x90/*P1*/, 2);/*P12*/
SBIT( M_4_A , 0x90/*P1*/, 3);/*P13*/

SBIT( LED1 , 0xA0/*P2*/, 0);/*P20*/

SBIT( BEEP , 0xA0/*P2*/, 5);/*P25*/

SBIT( LSA , 0xA0/*P2*/, 2);/*P22 A0*/
SBIT( LSB , 0xA0/*P2*/, 3);/*P23 A1*/
SBIT( LSC , 0xA0/*P2*/, 4);/*P24 A2*/


SBIT( KEY1 , 0xB0/*P3*/, 1);/*P31*/
SBIT( KEY2 , 0xB0/*P3*/, 0);/*P30*/
SBIT( KEY3 , 0xB0/*P3*/, 2);/*P32*/
SBIT( KEY4 , 0xB0/*P3*/, 3);/*P33*/

SBIT( HC595_SER , 0xB0/*P3*/, 4);/*P34 串行数据输入*/
SBIT( HC595_RCLK , 0xB0/*P3*/, 5);/*P35 存储寄存器时钟输入*/
SBIT( HC595_SRCLK , 0xB0/*P3*/, 6);/*P36 移位寄存器时钟输入*/

void delay_ms(unsigned int ms);
void delay_us(unsigned int us);

/** 
 * @brief LED D1闪烁
 * @param[in] void 
 * @return void 
 * @note 
 * @date 2024-11-05 21:46:07 
 * @version V1.0.0 
*/
void led1_ctrl(void);

/** 
 * @brief 实现LED流动水灯效果
 * @param[in] void 
 * @return void 
 * @note 
 * @date 2024-03-28 23:35:40 
 * @version V1.0.0 
*/
void led_flowing_water_lamp(void);

void beep_ctrl(void);

void beep_control(uint8_t count);

void nixie_tube_choose(uint8_t index, uint8_t number);

void nixie_tube_ctrl(void);

void key_matrix_check_flip(void);

void key_matrix_check_scan(void);

void key_scan(void);

void hc595_ctrl(void);
void hc595_one_init();

void hc595_one_write();

void hc595_write_one();

#endif